package com.gitee.wsl.time.calendar

import com.gitee.wsl.time.timestamp
import kotlin.time.Instant
import kotlinx.datetime.LocalDateTime
import kotlin.time.ExperimentalTime

interface Calendar {
    /**
     * Set a new base calendar or remove the existing one.
     *
     * @param baseCalendar
     * The new base calendar. May be `null`.
     */
    
    var baseCalendar: Calendar?

    /**
     * Set a description for the `Calendar` instance - may be useful
     * for remembering/displaying the purpose of the calendar, though the
     * description has no meaning to Quartz.
     *
     * @param description
     * The new description. May be `null`.
     */
    
    var description: String

    /**
     * Determine whether the given time (in milliseconds) is 'included' by the
     * Calendar.
     */
    fun isTimeIncluded(timeStamp: Long): Boolean

    /**
     * Determine the next time (in milliseconds) that is 'included' by the
     * Calendar after the given time.
     */
    fun getNextIncludedTime(timeStamp: Long): Long

    companion object {
        const val MONTH: Int = 0
    }
}

fun Calendar.isTimeIncluded(dataTime: LocalDateTime): Boolean = isTimeIncluded(dataTime.timestamp)

fun Calendar.getNextIncludedTime(dataTime: LocalDateTime) = getNextIncludedTime(dataTime.timestamp)

@OptIn(ExperimentalTime::class)
fun Calendar.isTimeIncluded(dataTime: Instant): Boolean = isTimeIncluded(dataTime.toEpochMilliseconds())

@OptIn(ExperimentalTime::class)
fun Calendar.getNextIncludedTime(dataTime: Instant) = getNextIncludedTime(dataTime.toEpochMilliseconds())